package com.example.android_learn;


import android.content.Context;
import android.util.Log;

import androidx.annotation.NonNull;
import androidx.lifecycle.Lifecycle;
import androidx.lifecycle.LifecycleObserver;
import androidx.lifecycle.LifecycleOwner;
import androidx.lifecycle.OnLifecycleEvent;

/**
 * Created by tony.zhang
 * Email: tony.zhang.Mr@foxmail.com
 */

public class MyObserver implements LifecycleObserver {
    private static final String TAG = "MyObserver";

    Context context;

    public MyObserver(Context context) {
        this.context = context;
    }

    @OnLifecycleEvent(Lifecycle.Event.ON_CREATE)
    public void onCreated(@NonNull LifecycleOwner owner) {
        Log.d(TAG, "onCreated: ");
        Log.d(TAG, "当前生命周期状态=" + owner.getLifecycle().getCurrentState());
    }

    @OnLifecycleEvent(Lifecycle.Event.ON_START)
    public void onStart(@NonNull LifecycleOwner owner) {
        Log.d(TAG, "onStart: ");
        Log.d(TAG, "当前生命周期状态=" + owner.getLifecycle().getCurrentState());
    }

    @OnLifecycleEvent(Lifecycle.Event.ON_RESUME)
    public void onResume(@NonNull LifecycleOwner owner) {
        Log.d(TAG, "onResume: ");
        Log.d(TAG, "当前生命周期状态=" + owner.getLifecycle().getCurrentState());
    }

    @OnLifecycleEvent(Lifecycle.Event.ON_PAUSE)
    public void onPause(@NonNull LifecycleOwner owner) {
        Log.d(TAG, "onPause: ");
        Log.d(TAG, "当前生命周期状态=" + owner.getLifecycle().getCurrentState());
    }

    @OnLifecycleEvent(Lifecycle.Event.ON_STOP)
    public void onStop(@NonNull LifecycleOwner owner) {
        Log.d(TAG, "onStop: ");
        Log.d(TAG, "当前生命周期状态=" + owner.getLifecycle().getCurrentState());
    }

}
